﻿using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;

namespace PasteLoggerBoard
{
    /// <summary>
    /// 
    /// </summary>
    [DependsOn(
        typeof(PasteLoggerBoardDomainModule),
        typeof(AbpEntityFrameworkCoreModule)
    )]
    public class PasteLoggerBoardEntityFrameworkCoreModule : AbpModule
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void ConfigureServices(ServiceConfigurationContext context)
        {

            //Console.WriteLine($"{DateTime.Now} PasteLoggerBoardEntityFrameworkCoreModule.ConfigureServices");

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            System.AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
            //判断什么数据库类型
            context.Services.AddTransient<IPasteLoggerBoardDbContext, PasteLoggerBoardDbContext>();
            Configure<AbpDbContextOptions>(options => { options.UseNpgsql(); });
            context.Services.AddAbpDbContext<PasteLoggerBoardDbContext>(options =>
            {
                options.AddDefaultRepositories<PasteLoggerBoardDbContext>(includeAllEntities: true);
            });

            base.PreConfigureServices(context);
        }
    }
}